home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9591 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: confusion between putchar and printf
  5. Date: 11 Mar 1996 15:24 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <11MAR199615245819@erich.triumf.ca>
  9. References: <4i1v2n$30o@news.azstarnet.com>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4i1v2n$30o@news.azstarnet.com>, Howard Salmon <captarm@azstarnet.com> writes...
  14. >K & R (section 1.5) states that "putchar(c) prints the contents of the 
  15. >integer variable c as a character, usually on the screen".
  16. >Here's a small program that I wrote testing putchar.  Why doesn't it 
  17. >compile?
  18. >#include <stdio.h>
  19. ># define A "hello world!"
  20. >main()
  21. >{
  22. >    int c;
  23. >    c =  A;
  24. >    putchar(A);
  25. >}
  26.  
  27. Hmmmm - an interesting concept.
  28.  
  29. What error messages does the compiler give when you try to compile this?
  30.  
  31. You have defined A to be a string literal. c = A; tries to force a pointer to
  32. that literal into an int, which is not legal.
  33.  
  34. If you had said
  35.     c = 'A';
  36. you would set c equal to the (ASCII) value of the letter 'A', and putchar()
  37. would print 'A' on the screen.
  38.  
  39. putchar() prints _only_ one char.
  40.  
  41.  
  42. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  43. Internet: bennett@triumf.ca         | of one another only when one can be
  44. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  45. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  46. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  47. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  48.  
  49.  
  50.  
  51.  
  52.